﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebDesign
{
    public class SqlClass
    {
        string cs = "Data Source=.;Initial Catalog=KaveComp;Integrated Security=True";
        public  void UseStoredProcedure( string NameStoreProcedure, SqlCommand cm)
        {
            cm.Connection=new SqlConnection(cs);
            cm.CommandType=CommandType.StoredProcedure;
            cm.CommandText=NameStoreProcedure;
            cm.Connection.Open();
            cm.ExecuteNonQuery();
            cm.Connection.Close();

        }
        public void Command(string sqlcom)
        {
            SqlCommand cm = new SqlCommand();
            cm.Connection = new SqlConnection(cs);
            cm.CommandType = CommandType.Text;
            cm.CommandText = sqlcom;
            cm.Connection.Open();
            cm.ExecuteNonQuery();
            cm.Connection.Close();

        }
        public void BindGridView(string sql,GridView gv)
        {
            SqlDataAdapter da=new SqlDataAdapter(sql,cs);
            DataSet ds=new DataSet();
            da.Fill(ds);
            gv.DataSource=ds.Tables[0];
            gv.DataBind();
        }
        public void BindCombobox(string sql,string ValueMember,string DisplayMember , DropDownList dd)
        {
            SqlDataAdapter da=new SqlDataAdapter(sql,cs);//connection string
            DataSet ds=new DataSet();
            da.Fill(ds);
            dd.DataValueField=ValueMember;
            dd.DataTextField=DisplayMember;
            dd.DataSource=ds.Tables[0];
            dd.DataBind();
        }
        public string checkCommand(string sql)
        {
            SqlCommand cm = new SqlCommand();
            cm.Connection = new SqlConnection(cs);
            cm.CommandType = CommandType.Text;
            cm.CommandText = sql;
            cm.Connection.Open();
            string chk = "";
            object obj = cm.ExecuteScalar();
            if (obj == DBNull.Value)
                chk = "";
            else
                chk = Convert.ToString(obj);
            return chk;


        }
       

    }
}